<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all"/>
    <link rel="stylesheet" href="__CSS__/admin.css" media="all">
    <style type="text/css">

        /* tooltip */
        #tooltip {
            position: absolute;
            border: 1px solid #ccc;
            background: #333;
            padding: 2px;
            display: none;
            color: #fff;
        }
    </style>
</head>
<body style="padding:10px;">
<div class="tplay-body-div">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">用户管理</li>
<!--            <li><a href="{:url('admin/user/publish')}" class="a_menu">新增用户</a></li>-->
        </ul>
    </div>
    <form class="layui-form search" action="{:url('admin/user/index')}" method="post">
        <div class="layui-form-item" style="float: left;">
            <div class="layui-input-inline">
                <input type="text" name="username" lay-verify="" autocomplete="off" placeholder="请输入昵称" class="layui-input layui-btn-sm"{notempty name="$post.username"
                       }value="{$post.username}" {/notempty}>
            </div>
            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">立即提交</button>
            <a href="" class="layui-btn layui-btn-sm" style="margin-right: 0;font-size:12px;">刷新</a>
        </div>
    </form>
    <table class="layui-table" lay-size="sm">
        <thead>
        <tr>
            <th>ID</th>
            <th>openid</th>
            <th>昵称</th>
            <th>角色</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="admin" id="vo" key="key"}
        <tr>
            <td>{$key}</td>
            <td>{$vo.openid}</td>
            <td>{$vo.username}</td>
            <td>
                {if condition="$vo.role eq 1 "}
                <button class="layui-btn layui-btn-normal layui-btn-sm">普通用户</button>
                {elseif condition="$vo.role eq 2"}
                <button class="layui-btn layui-btn-red layui-btn-sm">代理</button>
                {/if}
            </td>
            <td class="operation-menu">
                <div class="layui-btn-group">
                    <a href="{:url('admin/user/publish',['id'=>$vo.id])}" class="layui-btn layui-btn-sm "
                       style="margin-right: 0;font-size:12px;">开通权限</a>
<!--                    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-sm delete" id="{$vo.id}"-->
<!--                       style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i></a>-->
                </div>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div style="padding:0 20px;">{$admin->render()}</div>
    {include file="public/foot"}
    <script type="text/javascript">
            layui.use('layer', function () {
                var layer = layui.layer;

                $('.edit_password').click(function () {
                    var url = $(this).attr('href');
                    layer.open({
                        type: 2,
                        content: url,
                        area: ['600px', '480px'],
                        success: function(layero, index){
                            console.log(layero, index);
                        }
                    });
                    return false;
                })
            });

        $('.delete').click(function () {
            var id = $(this).attr('id');
            layer.confirm('确定要删除?', function (index) {
                $.ajax({
                    url: "{:url('admin/user/delete')}",
                    data: {id: id},
                    success: function (res) {
                        layer.msg(res.msg);
                        if (res.code == 1) {
                            setTimeout(function () {
                                location.href = res.url;
                            }, 1500)
                        }
                    }
                })
            })
        })
    </script>
    <script type="text/javascript">

        $('.is_logout').click(function () {
            var val = $(this).attr('data-val');
            var id = $(this).attr('data-id');
            var i = $(this).find('i');
            var the = $(this);
            if (val == 1) {
                var is_logout = 2;
            } else {
                var is_logout = 1;
            }
            $.ajax({
                type: "post",
                url: "{:url('admin/user/status')}",
                data: {is_logout: is_logout, id: id},
                success: function (res) {

                    if (res.code == 1) {
                        top();
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg);
                    }
                }
            })

            function top() {
                if (val == 1) {
                    i.attr("class", "fa fa-toggle-off");
                    the.attr('data-val', 0);
                } else {
                    i.attr("class", "fa fa-toggle-on");
                    the.attr('data-val', 1);
                }
            }
        })


    </script>
</div>
</body>
</html>
